<?php

/**
 * crpCalendar
 *
 * @copyright (c) 2007,2009 Daniele Conca
 * @link http://code.zikula.org/crpcalendar Support and documentation
 * @author Daniele Conca <conca.daniele@gmail.com>
 * @license GNU/GPL - v.2.1
 * @package crpCalendar
 */

Loader :: includeOnce('modules/crpCalendar/pnclass/crpCalendar.php');

/**
 * the main administration function
 *
 * @return string HTML output
 */
function crpCalendar_admin_main()
{
	// Security check
	if (!SecurityUtil :: checkPermission('crpCalendar::', '::', ACCESS_EDIT))
	{
		return LogUtil :: registerPermissionError();
	}

	// Create output object
	$render = &pnRender :: getInstance('crpCalendar', false);

	// Return the output that has been generated by this function
	return $render->fetch('crpcalendar_admin_main.htm');
}

/**
 * view items list
 *
 * @return string HTML output
 */
function crpCalendar_admin_view()
{
	// Security check
	if (!SecurityUtil :: checkPermission('crpCalendar::', '::', ACCESS_EDIT))
	{
		return LogUtil :: registerPermissionError();
	}

	$calendar = new crpCalendar();
	return $calendar->manageEvents();
}

/**
 * new item
 *
 * @return string HTML output
 */
function crpCalendar_admin_new()
{
	// Security check
	if (!SecurityUtil :: checkPermission('crpCalendar::', '::', ACCESS_EDIT))
	{
		return LogUtil :: registerPermissionError();
	}

	$calendar = new crpCalendar();
	return $calendar->newEvent();
}

/**
 * create item
 *
 * @return string HTML output
 */
function crpCalendar_admin_create()
{
	// Security check
	if (!SecurityUtil :: checkPermission('crpCalendar::', '::', ACCESS_EDIT))
	{
		return LogUtil :: registerPermissionError();
	}

	$calendar = new crpCalendar();
	return $calendar->createEvent();
}

/**
 * modify item
 *
 * @return string HTML output
 */
function crpCalendar_admin_modify()
{
	// Security check
	if (!SecurityUtil :: checkPermission('crpCalendar::', '::', ACCESS_EDIT))
	{
		return LogUtil :: registerPermissionError();
	}

	$calendar = new crpCalendar();
	return $calendar->modifyEvent();
}

/**
 * update item
 *
 * @return string HTML output
 */
function crpCalendar_admin_update()
{
	// Security check
	if (!SecurityUtil :: checkPermission('crpCalendar::', '::', ACCESS_EDIT))
	{
		return LogUtil :: registerPermissionError();
	}

	$calendar = new crpCalendar();
	return $calendar->updateEvent();
}

/**
 * clone item
 *
 * @return string HTML output
 */
function crpCalendar_admin_clone()
{
	// Security check
	if (!SecurityUtil :: checkPermission('crpCalendar::', '::', ACCESS_EDIT))
	{
		return LogUtil :: registerPermissionError();
	}

	$calendar = new crpCalendar();
	return $calendar->cloneEvent();
}

/**
 * modify item status
 *
 * @return string HTML output
 */
function crpCalendar_admin_change_status()
{
	// Security check
	if (!SecurityUtil :: checkPermission('crpCalendar::', '::', ACCESS_ADD))
	{
		return LogUtil :: registerPermissionError();
	}

	$calendar = new crpCalendar();
	return $calendar->changeStatus();
}

/**
 * delete item
 *
 * @return mixed string HTML output if no confirmation otherwise true
 */
function crpCalendar_admin_delete($args)
{
	// Security check
	if (!SecurityUtil :: checkPermission('crpCalendar::', '::', ACCESS_DELETE))
	{
		return LogUtil :: registerPermissionError();
	}

	$calendar = new crpCalendar();
	return $calendar->deleteEvent();
}

/**
 * delete item's file
 *
 * @return mixed string HTML output if no confirmation otherwise true
 */
function crpCalendar_admin_delete_file($args)
{
	// Security check
	if (!SecurityUtil :: checkPermission('crpCalendar::', '::', ACCESS_EDIT))
	{
		return LogUtil :: registerPermissionError();
	}

	$calendar = new crpCalendar();
	return $calendar->deleteFile();
}

/**
 * remove item
 *
 * @return mixed string HTML output if no confirmation otherwise true
 */
function crpCalendar_admin_remove($args)
{
	// Security check
	if (!SecurityUtil :: checkPermission('crpCalendar::', '::', ACCESS_DELETE))
	{
		return LogUtil :: registerPermissionError();
	}

	$calendar = new crpCalendar();
	return $calendar->removeEvent();
}

/**
 * modify module configuration
 *
 * @return string HTML output string
 */
function crpCalendar_admin_modifyconfig()
{
	// Security check
	if (!SecurityUtil :: checkPermission('crpCalendar::', '::', ACCESS_ADMIN))
	{
		return LogUtil :: registerPermissionError();
	}

	$calendar = new crpCalendar();
	return $calendar->modifyConfig();
}

/**
 * update module configuration
 *
 * @return string HTML output string
 */
function crpCalendar_admin_updateconfig()
{
	// Security check
	if (!SecurityUtil :: checkPermission('crpCalendar::', '::', ACCESS_ADMIN))
	{
		return LogUtil :: registerPermissionError();
	}

	$calendar = new crpCalendar();
	return $calendar->updateConfig();
}

/**
 * import events from an ical file
 *
 * @return string HTML output string
 */
function crpCalendar_admin_import_ical()
{
	// Security check
	if (!SecurityUtil :: checkPermission('crpCalendar::', '::', ACCESS_EDIT))
	{
		return LogUtil :: registerPermissionError();
	}
	$calendar = new crpCalendar();
	return $calendar->importIcs();
}

/**
 * insert events from an ical file
 *
 * @return string HTML output string
 */
function crpCalendar_admin_import_create()
{
	// Security check
	if (!SecurityUtil :: checkPermission('crpCalendar::', '::', ACCESS_EDIT))
	{
		return LogUtil :: registerPermissionError();
	}
	$calendar = new crpCalendar();
	return $calendar->createIcs();
}

/**
 * remove events older than a date
 *
 * @return string HTML output string
 */
function crpCalendar_admin_purge_events()
{
	// Security check
	if (!SecurityUtil :: checkPermission('crpCalendar::', '::', ACCESS_EDIT))
	{
		return LogUtil :: registerPermissionError();
	}
	$calendar = new crpCalendar();
	return $calendar->purgeEvents();
}

/**
 * remove items
 *
 * @return mixed string HTML output if no confirmation otherwise true
 */
function crpCalendar_admin_purge_remove($args)
{
	// Security check
	if (!SecurityUtil :: checkPermission('crpCalendar::', '::', ACCESS_DELETE))
	{
		return LogUtil :: registerPermissionError();
	}

	$calendar = new crpCalendar();
	return $calendar->removePurge();
}